package com.leoman.spinningmachine.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018-05-21.
 */

public class DateUtil {

    /**
     *
     * @return 返回今天string     yyyy-MM-dd
     */
    public static String getTodayStr(){
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(date);
    }

    /**
     * 返回年月日
     * @param time
     * @return        yyyy-MM-dd
     */
    public static String getyMdStr(long time){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(time);
    }
    /**
     * 返回指定格式的Str
     * @param time  long
     * @param str   String 指定格式
     * @return
     */
    public static String getyMdHms(long time,String str){
        SimpleDateFormat sdf = new SimpleDateFormat(str);
        return sdf.format(time);
    }

    /**
     * 获取指日期是当月第几天
     * @param str        yyyy-MM-dd
     * @return
     */
    public static String getDayOfMonth(String str){
        SimpleDateFormat sdf = new SimpleDateFormat("dd");
        return  sdf.format(str);
    }

    public static String getSxStr(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH");
        if(Integer.valueOf(sdf.format(time))>12){
            return "下午";
        }
        return "上午";
    }
}
